//
//  IdentityFourViewController.m
//  CommunityApp
//
//  Created by 秦乾龙 on 16/12/29.
//  Copyright © 2016年 秦乾龙. All rights reserved.
//

#import "IdentityFourViewController.h"
#import "ZYButton.h"
#import "NavView.h"
#import "WDData.h"
#import "WDViewController.h"
#define kScreenW [UIScreen mainScreen].bounds.size.width
#define kScreenH [UIScreen mainScreen].bounds.size.height
#define kScale   ([UIScreen mainScreen].bounds.size.width)/750

@interface IdentityFourViewController ()<UITextFieldDelegate,UITextViewDelegate,UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,retain) UITableView *mainTableView;
@property (nonatomic,copy) UITextField *nameField;
@property (nonatomic,copy) UITextField *ideNumField;
@property (nonatomic,copy) UITextField *phoneNumField;
@property (nonatomic,copy) UITextField *codeField;
@property (nonatomic,copy) NSMutableArray *classNameArr;
@property (nonatomic,copy) NSMutableArray *stepFinishedImgArr;
@property (nonatomic,copy) NSMutableArray *stepUnFinishedImgArr;
@end

@implementation IdentityFourViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _stepFinishedImgArr = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4", nil];
    _stepUnFinishedImgArr = [NSMutableArray arrayWithObjects:@"1灰",@"2灰",@"3灰",@"4灰", nil];
    [self setUI];
}
- (void) setUI
{
    self.navigationItem.titleView = [ViewFactory makeNavigationTitle:@"身份认证"];
    
    UIBarButtonItem *backBtn = [ViewFactory makeNavigationBackWhite:self action:@selector(backClick)];
    self.navigationItem.leftBarButtonItem = backBtn;
    
//    UIButton *buttonNotice = [UIButton buttonWithType:UIButtonTypeCustom];
//    buttonNotice.frame = CGRectMake(0, 0, 63, 20);
//    [buttonNotice setTitle:@"下一步" forState:UIControlStateNormal];
//    buttonNotice.titleLabel.font = [UIFont systemFontOfSize:13];
//    UIBarButtonItem *btnNoticeItem = [[UIBarButtonItem alloc]initWithCustomView:buttonNotice];
//    [buttonNotice addTarget:self action:@selector(nextClick) forControlEvents:UIControlEventTouchUpInside];
//    self.navigationItem.rightBarButtonItem = btnNoticeItem;
    

    _mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0,kScreenW , kScreenH-64) style:UITableViewStyleGrouped];
    _mainTableView.delegate = self;
    _mainTableView.dataSource = self;
    [self.view addSubview:_mainTableView];
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell)
    {
        cell =[[NSBundle mainBundle ]loadNibNamed:@"ZYTableViewCell" owner:nil options:nil][0];
    }
    
    //设置cell点击背景色不变
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    if (indexPath.section==0)
    {
        UIView *stateView = [[UIView alloc]init];
        stateView.frame = CGRectMake(0, 0, kScreenW, 200*kScale);
        stateView.backgroundColor = [UIColor whiteColor];
        [cell addSubview:stateView];
        NSMutableArray *lableTextArr = [NSMutableArray arrayWithObjects:@"填充信息",@"上传照片",@"选择收款方式",@"提交审核", nil];
        for (int i = 0; i<4; i++)
        {
            CGFloat errorW = 5*kScale;
            CGFloat stateBtnH = 82*kScale;
            CGFloat lineViewW = (kScreenW - 60*kScale -4*stateBtnH)/3+errorW;
            CGFloat lineViewH = 6*kScale;
            ZYButton *stateBtn = [ZYButton buttonWithType:UIButtonTypeCustom];
            
            
            stateBtn.frame = CGRectMake(30*kScale+(stateBtnH+lineViewW-errorW)*i, 30*kScale, stateBtnH, stateBtnH);
            
            if (i==3)
            {
                [stateBtn setImage:[UIImage imageNamed:_stepFinishedImgArr[i]] forState:UIControlStateNormal];
            }
            else
            {
                [stateBtn setImage:[UIImage imageNamed:_stepUnFinishedImgArr[i]] forState:UIControlStateNormal];
                
            }
            if (i!=0)
            {
                UIView *lineView = [[UIView alloc]init];
                lineView.frame = CGRectMake(30*kScale+(stateBtnH+lineViewW-errorW)*i-lineViewW+errorW/2, stateBtn.center.y, lineViewW, lineViewH);
                stateBtn.lineView = lineView;
                stateBtn.lineView.backgroundColor = ZallColorFromRGB(0x979797);
                [stateView addSubview:lineView];
                
            }
            
            [stateView addSubview:stateBtn];
            UILabel *stateLable = [[UILabel alloc]init];
            stateLable.text = lableTextArr[i];
            stateLable.frame = CGRectMake(0, 0, kScreenW, 40*kScale);
            stateLable.center = CGPointMake(stateBtn.center.x, stateBtn.center.y+stateBtnH/2+31*kScale);
            stateLable.textAlignment = NSTextAlignmentCenter;
            stateLable.font = [UIFont systemFontOfSize:13];
            [stateView addSubview:stateLable];
        }
    }
    else if (indexPath.section==1)
    {
        UIButton *boolSelectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [boolSelectBtn setImage:[UIImage imageNamed:@"提交审核成功"] forState:UIControlStateNormal];
        
        boolSelectBtn.frame = CGRectMake(300*kScale, 60*kScale, 100*kScale, 100*kScale);
        boolSelectBtn.center = CGPointMake(kScreenW/2, 110*kScale);
        
        [cell addSubview:boolSelectBtn];
        UILabel *payClassLable = [[UILabel alloc]init];
        payClassLable.text = @"成功提交审核，请耐心等待";
        payClassLable.font = [UIFont systemFontOfSize:15];
        payClassLable.frame = CGRectMake(0, 29*kScale, kScreenW, 42*kScale);
        payClassLable.center = CGPointMake(kScreenW/2, 240*kScale);
        payClassLable.textAlignment = NSTextAlignmentCenter;
        [cell addSubview:payClassLable];
    }
    else if (indexPath.section==2)
    {
        UILabel *classNameLable = [[UILabel alloc]init];
        classNameLable.text = [NSString stringWithFormat:@"您的身份信息:"];
        classNameLable.font = [UIFont systemFontOfSize:13];
        NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
        //        classNameLable.textColor = [UIColor colorWithRed:158/255.0 green:158/255.0 blue:158/255.0 alpha:1.0f];
        CGSize textSize = [classNameLable.text boundingRectWithSize:CGSizeMake(MAXFLOAT, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;;
        classNameLable.frame = CGRectMake(30*kScale, 0, textSize.width, 100*kScale);
        [cell addSubview:classNameLable];
        NSDate *date = [NSDate date];
        
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        
        
        [formatter setDateStyle:NSDateFormatterMediumStyle];
        
        [formatter setTimeStyle:NSDateFormatterShortStyle];
        
        [formatter setDateFormat:@"YYYY-MM-dd"];
        NSString *DateTime = [formatter stringFromDate:date];
        WDData *data = [WDData sharedWDData];
        NSMutableArray *classNameArr = [NSMutableArray arrayWithObjects:@"提交认证日期：",@"姓名：",@"身份证号码：", nil];
        NSMutableArray *contentArr = [NSMutableArray arrayWithObjects:DateTime,data.reallyName,data.idcar, nil];
        CGFloat classLableW = 298*kScale;
        CGFloat classLableH = 42*kScale;
        for (int i = 0; i<3; i++)
        {
            UILabel *classLable = [[UILabel alloc]init];
            classLable.frame = CGRectMake(30*kScale, 96*kScale+(42*kScale+30*kScale)*i, classLableW, classLableH);
            classLable.font = [UIFont systemFontOfSize:15];

            classLable.text = classNameArr[i];
            classLable.textAlignment = NSTextAlignmentRight;
            [cell addSubview:classLable];
            UILabel *contentLable = [[UILabel alloc]init];
            contentLable.frame = CGRectMake(30*kScale+classLableW, 96*kScale+(42*kScale+30*kScale)*i, kScreenW, 42*kScale);
//            NSString *str1 = @"当前绑定手机号:";
            contentLable.text = contentArr[i];
            contentLable.font = [UIFont systemFontOfSize:15];
            contentLable.textColor = ZallColorFromRGB(0xA5A5A5);
            [cell addSubview:contentLable];
        }
        
    }
    
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        return 200*kScale;
    }
    else if (indexPath.section==1)
    {
        return 322*kScale;
    }
    return  352*kScale;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return  0.01;
    }
    return 20*kScale;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}
- (void)backClick
{
    for (UIViewController *temp in self.navigationController.viewControllers) {
        if ([temp isKindOfClass:[WDViewController class]]) {
            [self.navigationController popToViewController:temp animated:YES];
        }
    } ;

    
    
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
